package com.pzsh.aliyun.api.gateway.demo;

import com.pzsh.aliyun.api.gateway.demo.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:阿里云市场银行卡实名认证接口
 * @Param:
 * @return:
 * @Author: GXL
 * @Date: 2019/12/12
 */
@Slf4j
public class BankAuth {

//    private static final String APP_CODE = "b8597396156948c6afa14a1dcea97277";
//    private static final String APP_KEY = "203769998";
//    private static final String APP_SECRET = "p2ws9gzntsmgwea35mye6rzh2okh855k";


    private static final String APP_CODE = "9ec46a813f4843f9a984f1c1c7159159";
    private static final String APP_KEY = "203769298";
    private static final String APP_SECRET = "i59b5tc3qclj5dl7o0dpj4imauosq4b4";

    public static String check(String cardNumber,String idNumber, String name, String phoneNumber) {
        String host = "https://4bankcard.market.alicloudapi.com";
        String path = "/getapilist/";
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + APP_CODE);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("card_number", cardNumber);
        querys.put("id_number", idNumber);
        querys.put("name", name);
        querys.put("phone_number", phoneNumber);
        Map<String, String> bodys = new HashMap<String, String>();

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
//            System.out.println("1111 ==="+response.toString());
            //获取response的body
            String res = EntityUtils.toString(response.getEntity());
            log.info("【前端】银行卡实名认证结果：{}", res);
            return res;
        } catch (Exception e) {
            log.error(e.getLocalizedMessage());
        }
        return null;
    }
}
